<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>My Homework -- 所有小组</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel='stylesheet' type='text/css' media='all' href='__TMPL__Public/css/book.css' />
		<script src="__TMPL__Public/jquery/js/jquery-1.6.2.min.js" type="text/javascript" ></script>
		<script src="__TMPL__Public/jquery/js/jquery-ui-1.8.16.custom.min.js" type="text/javascript" ></script>
		<script type="text/javascript" src="__TMPL__Group/js/group.js" ></script>
		<script type="text/javascript" src="__TMPL__Group/js/create.js" ></script>
		<script type="text/javascript" >
			$(function() {

				$(".join_group_button").bind('click', function() {
					var group_id = $(this).attr('group_id');
					joinGroup(group_id, this);
				});
				$("#form1").submit(function(event) {

					/* stop form from submitting normally */
					event.preventDefault();

					/* get some values from elements on the page: */
					var $form = $(this), url = $form.attr('action');

					/* Send the data using post and put the results in a div */
					$.post(url, $("#form1").serialize(), function(result) {
						result = JSON.parse(result);
						if(result.status == 1) {
							alert("创建成功");
							window.location = "__APP__/Group/myGroup";
						} else {
							if(result.info == null){
								alert("您已经是某个小组的成员");
							}
							else{
								alert(result.info);
							}
						}
					});
				});
			});
			function joinGroup(group_id, button) {

				$.get("__APP__/Group/join", {
					group_id : group_id
				}, function(result) {
					result = JSON.parse(result);
					if(result.status == 1) {
						alert("加入成功");
						window.location = "__APP__/Group/myGroup";
					} else {
						if(result.info == null){
								alert("您已经是某个小组的成员");
							}
							else{
								alert(result.info);
							}
					}
				});
			}
		</script>
	</head>
	<body id="threeColLayout" class="home">
		<div id="wrapper">
			<div id="header">
				<h1>My Homework</h1>
				<ul id="mainNav">
					<li>
						<a href="__APP__/Index/studentMain" id="home">我的主页</a>
					</li>
					<li>
						<a href="__APP__/Group/myGroup">我的小组</a>
					</li>
					<li>
						<a href="__APP__/Group/allGroups">所有小组</a>
					</li>
					<li>
						<a href="__APP__/Login/logout">退出</a>
					</li>
				</ul>
			</div><!-- end #header -->
			<div id="primaryContent">
				<div class="box interviews">
					<h2>所有小组</h2>
					<div class="cbb">
						<table border="1">
							<tr>
								<th>序号</th>
								<th>组名</th>
								<th>组长</th>
								<th>操作</th>
							</tr>
							<volist name="groups" id="vo" key="k">
								<tr>
									<td>{$k}</td>
									<td><a href="__APP__/Group/groupPage?group_id={$vo['id']}">{$vo['name']}</a></td>
									<td>{$vo['leadername']}</td>
									<td>
									<button class="buttons join_group_button" group_id="{$vo['id']}">
										加入
									</button></td>
								</tr>
							</volist>
						</table>
					</div>
				</div>
			</div>
			<!-- end #primaryContent -->
			<div id="sideContent">
				<div class="box">
					<h2>个人信息</h2>
					<div class="cbSide">
						<h3>姓名：</h3><h3>{$student['name']}</h3>
						<br/>
						<h3>学号：</h3><h3>{$student['studentid']}</h3>
						<br/>
					</div>
				</div>
				<div id="button">
					<br/>
					<button id="dialog" href="#create">
						创建小组
					</button>
				</div>
			</div>
			<!-- end #sideContent -->
			<div id="footer"></div>
			<!-- end #footer -->
		</div><!-- end #wrapper -->
		<div id="create">
			<form action = "__APP__/Group/add" name="create_group" id="form1" method="post">
				小组名
				<input type="text" id="groupname" name="groupname"/>
				<input type="submit" id="_submit" name="submit" value="创建"/>
			</form>
		</div>
		<div id="lean_overlay" style="display: none; opacity: 0.5; "></div>
	</body>
</html>